package java8.stream.demo01;

import com.google.common.base.Stopwatch;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author ChangLiang
 * @date 2020/4/22
 */
public class AppTest extends AbstractDishBeforeTest {

    @Test
    @DisplayName("test collections")
    public void test() {
        Stopwatch stopwatch = Stopwatch.createStarted();
        List<String> dishNames = DishService.getDishNamesByCollections(menu);
        // output: 3
        System.out.printf("collections elapsed: %d%n", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        System.out.println(dishNames);
    }


    @Test
    @DisplayName("test stream")
    public void test2() {
        Stopwatch stopwatch = Stopwatch.createStarted();
        List<String> dishNames = DishService.getDishNamesByStream(menu);
        // output: 2
        System.out.printf("test stream elapsed: %d%n", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        System.out.println(dishNames);
    }

    @Test
    @DisplayName("test parallel stream")
    public void test3() {
        Stopwatch stopwatch = Stopwatch.createStarted();
        List<String> dishNames = DishService.getDishNamesByStreamParallel(menu);
        // output: 9
        System.out.printf("test parallel stream: %d%n", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        System.out.println(dishNames);
    }

    @Test
    @DisplayName("test stream by log")
    public void test4(){
        Stopwatch stopwatch = Stopwatch.createStarted();
        List<String> dishNames = DishService.getDishNamesWithStreamLog(menu);
        System.out.printf("test stream by log: %d%n", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        System.out.println(dishNames);
    }

}
